package com.controller;
import com.entity.Goods;
import com.service.GoodsService;
import com.service.CommentService;
import com.util.CodeMsg;
import com.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/goods")
public class GoodsController {

    @Autowired
    private GoodsService goodsService;

    @Autowired
    private CommentService commentService;

    @GetMapping(value = "")
    public Result<List<Goods>> listGoods() {
        List<Goods> goodsList = goodsService.findAll();
        return Result.success(goodsList);
    }

    @GetMapping(value = "/{id}")
    public Result<Goods> getGoodsDetail(@PathVariable Long id) {
        Goods goods = goodsService.findById(id);
        if (goods == null) {
            return Result.error(new CodeMsg(404, "商品不存在"));
        }
        return Result.success(goods);
    }
}